import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
export class BaseApiResponse<T, U> {
  public data: T;

  @ApiProperty({ type: Object })
  public meta: U;
}
export function SwaggerBaseApiResponse<T, U>(
  name: string,
  type: T,
  meta?: U,
): typeof BaseApiResponse {
  class ExtendedBaseApiResponse<T, U> extends BaseApiResponse<T, U> {
    @ApiProperty({ type })
    public data: T;
    @ApiProperty({ type: meta })
    public meta: U;
  }
  Object.defineProperty(ExtendedBaseApiResponse, 'name', {
    value: `${name}`,
  });

  return ExtendedBaseApiResponse;
}
export class BaseApiErrorObject {
  @ApiProperty({ type: Number })
  public statusCode: number;

  @ApiProperty({ type: String })
  public message: string;

  @ApiPropertyOptional({ type: String })
  public localizedMessage: string;

  @ApiProperty({ type: String })
  public errorName: string;

  @ApiProperty({ type: Object })
  public details: unknown;

  @ApiProperty({ type: String })
  public path: string;

  @ApiProperty({ type: String })
  public requestId: string;

  @ApiProperty({ type: String })
  public timestamp: string;
}
export class BaseApiErrorResponse {
  @ApiProperty({ type: BaseApiErrorObject })
  public error: BaseApiErrorObject;
}
